package com.cetus.jengine.orm.ext.liferay.testportlet.model.impl;

import com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember;
import com.cetus.jengine.orm.ext.liferay.testportlet.model.SMemberModel;
import com.cetus.jengine.orm.ext.liferay.testportlet.model.SMemberSoap;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the SMember service. Represents a row in the &quot;SB_SMember&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.cetus.jengine.orm.ext.liferay.testportlet.model.SMemberModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link SMemberImpl}.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see SMemberImpl
 * @see com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember
 * @see com.cetus.jengine.orm.ext.liferay.testportlet.model.SMemberModel
 * @generated
 */
@JSON(strict = true)
public class SMemberModelImpl extends BaseModelImpl<SMember>
    implements SMemberModel {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. All methods that expect a s member model instance should use the {@link com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember} interface instead.
     */
    public static final String TABLE_NAME = "SB_SMember";
    public static final Object[][] TABLE_COLUMNS = {
            { "memberId", Types.BIGINT },
            { "libraryId", Types.BIGINT },
            { "firstName", Types.VARCHAR },
            { "lastName", Types.VARCHAR }
        };
    public static final String TABLE_SQL_CREATE = "create table SB_SMember (memberId LONG not null primary key,libraryId LONG,firstName VARCHAR(75) null,lastName VARCHAR(75) null)";
    public static final String TABLE_SQL_DROP = "drop table SB_SMember";
    public static final String DATA_SOURCE = "liferayDataSource";
    public static final String SESSION_FACTORY = "liferaySessionFactory";
    public static final String TX_MANAGER = "liferayTransactionManager";
    public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.entity.cache.enabled.com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember"),
            true);
    public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
                "value.object.finder.cache.enabled.com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember"),
            true);
    public static final boolean COLUMN_BITMASK_ENABLED = false;
    public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
                "lock.expiration.time.com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember"));
    private static ClassLoader _classLoader = SMember.class.getClassLoader();
    private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
            SMember.class
        };
    private long _memberId;
    private long _libraryId;
    private String _firstName;
    private String _lastName;
    private SMember _escapedModelProxy;

    public SMemberModelImpl() {
    }

    /**
     * Converts the soap model instance into a normal model instance.
     *
     * @param soapModel the soap model instance to convert
     * @return the normal model instance
     */
    public static SMember toModel(SMemberSoap soapModel) {
        if (soapModel == null) {
            return null;
        }

        SMember model = new SMemberImpl();

        model.setMemberId(soapModel.getMemberId());
        model.setLibraryId(soapModel.getLibraryId());
        model.setFirstName(soapModel.getFirstName());
        model.setLastName(soapModel.getLastName());

        return model;
    }

    /**
     * Converts the soap model instances into normal model instances.
     *
     * @param soapModels the soap model instances to convert
     * @return the normal model instances
     */
    public static List<SMember> toModels(SMemberSoap[] soapModels) {
        if (soapModels == null) {
            return null;
        }

        List<SMember> models = new ArrayList<SMember>(soapModels.length);

        for (SMemberSoap soapModel : soapModels) {
            models.add(toModel(soapModel));
        }

        return models;
    }

    public long getPrimaryKey() {
        return _memberId;
    }

    public void setPrimaryKey(long primaryKey) {
        setMemberId(primaryKey);
    }

    public Serializable getPrimaryKeyObj() {
        return new Long(_memberId);
    }

    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    public Class<?> getModelClass() {
        return SMember.class;
    }

    public String getModelClassName() {
        return SMember.class.getName();
    }

    @Override
    public Map<String, Object> getModelAttributes() {
        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("memberId", getMemberId());
        attributes.put("libraryId", getLibraryId());
        attributes.put("firstName", getFirstName());
        attributes.put("lastName", getLastName());

        return attributes;
    }

    @Override
    public void setModelAttributes(Map<String, Object> attributes) {
        Long memberId = (Long) attributes.get("memberId");

        if (memberId != null) {
            setMemberId(memberId);
        }

        Long libraryId = (Long) attributes.get("libraryId");

        if (libraryId != null) {
            setLibraryId(libraryId);
        }

        String firstName = (String) attributes.get("firstName");

        if (firstName != null) {
            setFirstName(firstName);
        }

        String lastName = (String) attributes.get("lastName");

        if (lastName != null) {
            setLastName(lastName);
        }
    }

    @JSON
    public long getMemberId() {
        return _memberId;
    }

    public void setMemberId(long memberId) {
        _memberId = memberId;
    }

    @JSON
    public long getLibraryId() {
        return _libraryId;
    }

    public void setLibraryId(long libraryId) {
        _libraryId = libraryId;
    }

    @JSON
    public String getFirstName() {
        if (_firstName == null) {
            return StringPool.BLANK;
        } else {
            return _firstName;
        }
    }

    public void setFirstName(String firstName) {
        _firstName = firstName;
    }

    @JSON
    public String getLastName() {
        if (_lastName == null) {
            return StringPool.BLANK;
        } else {
            return _lastName;
        }
    }

    public void setLastName(String lastName) {
        _lastName = lastName;
    }

    @Override
    public ExpandoBridge getExpandoBridge() {
        return ExpandoBridgeFactoryUtil.getExpandoBridge(0,
            SMember.class.getName(), getPrimaryKey());
    }

    @Override
    public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
        ExpandoBridge expandoBridge = getExpandoBridge();

        expandoBridge.setAttributes(serviceContext);
    }

    @Override
    public SMember toEscapedModel() {
        if (_escapedModelProxy == null) {
            _escapedModelProxy = (SMember) ProxyUtil.newProxyInstance(_classLoader,
                    _escapedModelProxyInterfaces,
                    new AutoEscapeBeanHandler(this));
        }

        return _escapedModelProxy;
    }

    @Override
    public Object clone() {
        SMemberImpl sMemberImpl = new SMemberImpl();

        sMemberImpl.setMemberId(getMemberId());
        sMemberImpl.setLibraryId(getLibraryId());
        sMemberImpl.setFirstName(getFirstName());
        sMemberImpl.setLastName(getLastName());

        sMemberImpl.resetOriginalValues();

        return sMemberImpl;
    }

    public int compareTo(SMember sMember) {
        long primaryKey = sMember.getPrimaryKey();

        if (getPrimaryKey() < primaryKey) {
            return -1;
        } else if (getPrimaryKey() > primaryKey) {
            return 1;
        } else {
            return 0;
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        SMember sMember = null;

        try {
            sMember = (SMember) obj;
        } catch (ClassCastException cce) {
            return false;
        }

        long primaryKey = sMember.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public void resetOriginalValues() {
    }

    @Override
    public CacheModel<SMember> toCacheModel() {
        SMemberCacheModel sMemberCacheModel = new SMemberCacheModel();

        sMemberCacheModel.memberId = getMemberId();

        sMemberCacheModel.libraryId = getLibraryId();

        sMemberCacheModel.firstName = getFirstName();

        String firstName = sMemberCacheModel.firstName;

        if ((firstName != null) && (firstName.length() == 0)) {
            sMemberCacheModel.firstName = null;
        }

        sMemberCacheModel.lastName = getLastName();

        String lastName = sMemberCacheModel.lastName;

        if ((lastName != null) && (lastName.length() == 0)) {
            sMemberCacheModel.lastName = null;
        }

        return sMemberCacheModel;
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(9);

        sb.append("{memberId=");
        sb.append(getMemberId());
        sb.append(", libraryId=");
        sb.append(getLibraryId());
        sb.append(", firstName=");
        sb.append(getFirstName());
        sb.append(", lastName=");
        sb.append(getLastName());
        sb.append("}");

        return sb.toString();
    }

    public String toXmlString() {
        StringBundler sb = new StringBundler(16);

        sb.append("<model><model-name>");
        sb.append("com.cetus.jengine.orm.ext.liferay.testportlet.model.SMember");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>memberId</column-name><column-value><![CDATA[");
        sb.append(getMemberId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>libraryId</column-name><column-value><![CDATA[");
        sb.append(getLibraryId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>firstName</column-name><column-value><![CDATA[");
        sb.append(getFirstName());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>lastName</column-name><column-value><![CDATA[");
        sb.append(getLastName());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
